home *** CD-ROM | disk | FTP | other *** search
- /*{{{}}}*/
- /*{{{ #includes*/
- #include <ctype.h>
- #include <string.h>
- #include <stdlib.h>
- #include <stdio.h>
-
- #define NAME_C
-
- #include "keybind.h"
- /*}}} */
-
- /*{{{ type name_code*/
- typedef struct { char *name;char *code; } name_code;
- /*}}} */
-
- #include "autotoken.h"
-
- /*{{{ cmp*/
- int cmp(const void *a, const void *b)
- {
- return(strcmp(((name_code*)a)->name,((name_code*)b)->name));
- }
- /*}}} */
- /*{{{ sort_and_print*/
- void sort_and_print(name_code *list,char *type,char *name,int use)
- {
- size_t n;
-
- /*{{{ sort the names*/
- { name_code *x;
-
- for (n=0,x=list;x->name;n++,x++);
- qsort(list,n,sizeof(name_code),cmp);
- }
- /*}}} */
- /*{{{ print the list*/
- printf("/*{{{ %s*/\n",name);
- /*{{{ print sizes*/
- { size_t x;
-
- printf("#define N_%s %d\n",name,n);
- for (x=1;x<n;x=x<<1);
- printf("#define S_%s %d\n",name,x>>1);
- }
- /*}}} */
- printf("public %s %s[]={\n",type,name);
- /*{{{ print list of names/codes*/
- for (;list->name;list++)
- printf(" {(unsigned char*)\"%s\",%s%s},\n",list->name,list->code,use?",1":"");
- /*}}} */
- printf(" {0,%s%s}\n};\n",list->code?list->code:"0",use?",0":"");
- printf("/*}}}*/\n");
- /*}}} */
- }
- /*}}} */
- /*{{{ main*/
- int main()
- {
- printf("#ifndef MESSAGES_C\n");
- /*{{{ handle constant names*/
- printf("/*{{{ single names*/\n");
- { name_code *x;
-
- for (x=singles;x->name;x++)
- printf("public unsigned char const %s[]=\"%s\";\n",x->code,x->name);
- }
- printf("/*}}}*/\n");
- /*}}} */
- /*{{{ handle keybindings table*/
- sort_and_print(binding_names,"KEYNAME","bindings",1);
- /*}}} */
- /*{{{ handle keyword table*/
- sort_and_print(keytab_names,"keywords const","keytab",0);
- /*}}} */
- /*{{{ handle asm-token table*/
- sort_and_print(asm_token_names,"KEYNAME const","asm_token",1);
- /*}}} */
- printf("#else\n");
- /*{{{ handle string defines*/
- printf("/*{{{ name defines*/\n");
- { name_code *x;
-
- for (x=keytab_names;x->name;x++)
- printf
- ( "#ifndef %s_STR\n# define %s_STR \"%s\"\n#endif\n",
- x->code,
- x->code,
- x->name
- );
- for (x=singles;x->name;x++)
- printf
- ( "#ifndef %s_STR\n# define %s_STR \"%s\"\n#endif\n",
- x->code,
- x->code,
- x->name
- );
- }
- printf("/*}}}*/\n");
- /*}}} */
- printf("#endif\n");
-
- return(0);
- }
- /*}}} */
-